<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/13
  Time: 9:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="application/javascript" src="static/jquery-3.6.1.min.js"></script>
</head>
<body>
<%-- --%>

<form>
    用户名: <input type="text" name="username" id="username"  onblur="checkUsername(this)"/><br>
    密码:<input type="password" name="password"><br>
   <input type="button" onclick="subuser()">
</form>
<table >
    <tr>
        <th>id</th>
        <th>用户名</th>
        <th>密码</th>
        <th>操作</th>
    </tr>
    <tbody id="tb"></tbody>
</table>

<script>
    //
    $(function(){
        $.get("getAllUser",{},function(data){
            // alert(data.length);  【{id=1,username='',password=''}，{}，{}，{}】
            alert(JSON.stringify(data));
            var trs="";
            for(var i=0;i<data.length;i++){
                trs+="<tr>" +
                    "<td>"+data[i].id+"</td>" +
                    "<td>"+data[i].username+"</td>" +
                    "<td>"+data[i].password+"</td>" +
                    "<td><a href='#' onclick='updUser("+data[i].id+")'>修改</a><a href='#' onclick='delUser("+data[i].id+")'>删除</a></td>" +
                    "</tr>"
            }
            $("#tb").html(trs);

        })

    });



    function updUser(uid){
        console.log(uid);
        //
        $.post("updUser/"+uid,{},function(d){
            console.log(d);
        });
    }

    function delUser(uid){
        console.log(uid);
        //
        $.get("delUser/"+uid,{},function(d){
            console.log(d);
        });
    }


  function checkUsername(obj){
      // 获取当前的文本框中的内容
     var username= obj.value;
     console.log(username);
     //
      $.ajax({
          type:"post",
          url:"checkUsername",
          data:{name:username},
          success:function(d){
              if(d==1){
               alert("该用户已经存在！！！");
              }else{
                  alert("可以注册！！！");
              }

          }

      })
  }




</script>

</body>
</html>
